home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7576 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.8 KB  |  87 lines

  1. Newsgroups: comp.lang.c++
  2. Path: news.ner.bbnplanet.net!arco!usenet
  3. From: Brian Leach <lasbfl>
  4. Subject: Re: How to prototype a class?
  5. X-Nntp-Posting-Host: 136.226.116.1
  6. Content-Type: text/plain; charset=us-ascii
  7. Message-ID: <Dn9449.1FB@news.arco.com>
  8. Sender: usenet@news.arco.com
  9. Content-Transfer-Encoding: 7bit
  10. Organization: ARCO Oil % Gas Company
  11. References: <4fvjhe$c6o@nuntius.u-net.net> <DMtxzu.8HK@tr.unisys.com> <4g9rrr$78s@news.NetVision.net.il>
  12. Mime-Version: 1.0
  13. Date: Fri, 23 Feb 1996 23:04:57 GMT
  14. X-Mailer: Mozilla 1.12 (X11; I; HP-UX A.09.05 9000/755)
  15. X-Url: news:4g9rrr$78s@news.NetVision.net.il
  16.  
  17. Ivan Krivyakov <ivan@cmt.co.il> wrote:
  18. >"Benjamin M. Romer" <bmr1@trpo4.tr.unisys.com> wrote:
  19. >
  20. >> Use a forward declaration:
  21. >> 
  22. >> class A;      //I promise to define A later.
  23. >>
  24. >> class B
  25. >> {
  26. >>  ...
  27. >> private:
  28. >>     A dataMember; // <--- here is an error!
  29. >> };
  30. >>
  31. >> Class A
  32. >> {
  33. >>  ...
  34. >> private:
  35. >>    B dataMember;
  36. >> };
  37. >>
  38. >> Hope this helps.
  39. >>
  40. >> Benjamin M. Romer
  41. >
  42. >Sorry, but this won't work!
  43. >
  44. >In the point where you declare B::dataMember, class A is not still defined
  45. >although compiler knowns that it exists.
  46. >
  47. >To process a declaration of B::dataMember compiler should know, for example, 
  48. >what is the size of objects of type A. This is obviously not known for one-pass compiler
  49. >in the point where B::dataMember is declared.
  50. >
  51. >You may use pointer to A instead of A as follows:
  52. >
  53. >class A;
  54. >
  55. >class B
  56. >{
  57. >  ...
  58. >  A* dataMember; //<--- legal
  59. >  ...
  60. >};
  61. >
  62. >> #include <stddisclaim.h>
  63. >
  64. >Good idea! :)
  65. >
  66. >Best regards,
  67. >Ivan (ivan@cmt.co.il)
  68. >
  69. >
  70. If you don't use pointers, isn't this an infinitely recursive class?
  71. Hope you have a lot of memory...
  72.  
  73.  
  74. -- 
  75. Brian F. Leach
  76. Sr. Systems Analyst
  77. lasbfl@aai.arco.com
  78.  
  79. Telephone:    (907) 263-4860
  80. FAX:        (907) 265-6298
  81.  
  82. ARCO Alaska, Inc.
  83. ATO-1656
  84. P.O. Box 100360
  85. Anchorage, AK 99510-0360
  86.  
  87.